package cn.maigc.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

//封装统一返回值类型
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResultVo {
    private String msg; //返回消息
    private Integer code; //状态码
    private Object data;

    public static ResultVo  vo(String msg,Integer code,Object data){
        return new ResultVo(msg,code,data);
    }

    //成功
    public static ResultVo success(){
        return vo("请求成功！",StatusCode.SUCCESS_CODE,null);
    }
    public static ResultVo success(String msg){
        return vo(msg,StatusCode.SUCCESS_CODE,null);
    }
    public static ResultVo success(String msg,Object data){
        return vo(msg,StatusCode.SUCCESS_CODE,data);
    }
    public static ResultVo success(String msg,Integer code,Object data){
        return vo(msg,code,data);
    }

    //失败
    public static ResultVo error(){
        return vo("请求成功！",StatusCode.ERROR_CODE,null);
    }
    public static ResultVo error(String msg){
        return vo(msg,StatusCode.ERROR_CODE,null);
    }
    public static ResultVo error(String msg,Object data){
        return vo(msg,StatusCode.ERROR_CODE,data);
    }
    public static ResultVo error(String msg,Integer code,Object data){
        return vo(msg,code,data);
    }
}
